#! /bin/sh -vx
# $Id$
# Copyright 2022 Japanese TeX Development Community <issue@texjp.org>
# Copyright 2017 Karl Berry <tex-live@tug.org>
# Copyright 2013 Peter Breitenlohner <tex-live@tug.org>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_uppltotf=$BinDir/uppltotf$ExeExt
_uptftopl=$BinDir/uptftopl$ExeExt

test -d uptests || mkdir -p uptests

TEXMFCNF=$srcdir/../kpathsea
export TEXMFCNF

# Test inputs
testdir=$srcdir/uptexdir/tests

# Testing upPLtoTF/upTFtoPL for umin10 (yoko=horiz) and utmin10 (tate=vert).
for font in umin10 utmin10; do

  $_uppltotf -verbose $testdir/$font.pl uptests/x$font.tfm && \
    cmp $testdir/$font.tfm uptests/x$font.tfm && echo || exit 1

  $_uptftopl -charcode-format octal -verbose $testdir/$font.tfm uptests/x$font.pl && \
    diff $testdir/$font.pl uptests/x$font.pl && echo || exit 2

done


# Test inputs
testdir=$srcdir/ptexdir/tests

# Testing pPLtoTF/pTFtoPL compatible mode for character range & encoding.
for font in chcode; do

  $_uppltotf -kanji=utf8 $testdir/$font.pl uptests/x$font.tfm && \
    cmp $testdir/$font.tfm uptests/x$font.tfm && echo || exit 3

  $_uptftopl -kanji=utf8 -charcode-format octal $testdir/$font.tfm uptests/x$font.pl && \
    diff $testdir/$font.pl uptests/x$font.pl && echo || exit 4

for enc in utf8 euc sjis jis; do

  $_uppltotf -kanji=$enc $testdir/$font-$enc.pl uptests/x$font-$enc.tfm && \
    cmp $testdir/$font.tfm uptests/x$font-$enc.tfm && echo || exit 5

  $_uptftopl -kanji=$enc $testdir/$font.tfm uptests/x$font-$enc.pl && \
    if [ $enc = utf8 ]; then \
      perl -i".orig" -CD -pe "use utf8; tr/―～∥－￠￡￢/—〜‖−¢£¬/" uptests/x$font-$enc.pl; fi && \
    diff $testdir/$font-$enc.pl uptests/x$font-$enc.pl && echo || exit 6

  if [ $enc = utf8 ]; then
    $_uppltotf -kanji=$enc uptests/x$font-$enc.pl.orig uptests/x$font-$enc.tfm && \
      cmp $testdir/$font.tfm uptests/x$font-$enc.tfm && echo || exit 7
  fi

done
done
